<?php
/**
 * 缓存适配器
 * @author Yuwei(yuwei1122@gmail.com)
 *
 */
class BluePhp_Library_Cache_Adapter 
{
	/**
	 * 驱动
	 *
	 * @var unknown_type
	 */
	protected static $_drive;
	
	/**
	 * 初始化
	 */
	protected static function _initialization()
	{
		if(!self::$_drive)
			switch (CACHE_TYPE)
			{
				case 'apc':
					self::$_drive = new BluePhp_Library_Cache_Drives_Apc();
				break;
				case 'memcache':
				default:
					self::$_drive = new BluePhp_Library_Cache_Drives_Memcache();
				break;
			}
	}
	
	/**
	 * 获取一个key值
	 *
	 * @param unknown_type $key
	 * @return unknown
	 */
	public static function get($key)
	{
		self::_initialization();
		return self::$_drive->get($key);
	}
	
	/**
	 * 添加一个值，如果已经存在，则覆写
	 *
	 * @param unknown_type $key
	 * @param unknown_type $value
	 */
	public static function set($key,$value,$time = CACHE_LIFETIME)
	{
		self::_initialization();
		return self::$_drive->set($key,$value,$time);
	}
	
	/**
	 * 删除一个key值,会释放该key所使用的内存空间
	 *
	 * @param unknown_type $key
	 */
	public static function delete($key)
	{
		self::_initialization();
		return self::$_drive->delete($key);
	}
	
	/**
	 * 对一个已有的key进行覆写操作
	 *
	 * @param unknown_type $key
	 * @param unknown_type $value
	 */
	public static function replace($key,$value)
	{
		self::_initialization();
		return self::$_drive->replace($key,$value);
	}
	
	/**
	 * 清除所有缓存,不会释放已使用内存空间
	 *
	 */
	public static function flush()
	{
		self::_initialization();
		return self::$_drive->flush();
	}
}
?>